//
//  LoginViewController.swift
//  Neufood
//
//  Created by Mac  on 2017/9/23.
//  Copyright © 2017年 Mac . All rights reserved.
//

import UIKit

class LoginViewController: UIViewController {

    @IBOutlet weak var username: UITextField!

    @IBOutlet weak var userpass: UITextField!
 
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    @IBAction func Login(_ sender: UIButton) {
        
        if username.text?.characters.count==0
        {
           
            MBProgressHUD.showTextDialog(self.view, message: "请输入用户名")
        }
        else{
            if userpass.text?.characters.count==0
            {
                
                MBProgressHUD.showTextDialog(self.view, message: "请输入密码")
            }
            
            let Login_url:String = "http://60.205.189.39/userLogin.do"
            let parameters:NSDictionary=["username":username.text!,"userpass":userpass.text!]
            let manager = AFHTTPRequestOperationManager()
            
            manager.get(Login_url, parameters: parameters, success: { (operation:AFHTTPRequestOperation?, responseObject:Any?) in
                
                print(responseObject!)
                
                let success = (responseObject as! NSDictionary).object(forKey: "userid")  as! NSString
               
                if success != "0"
                {
                    MBProgressHUD.showTextDialog(self.view, message: "登陆成功")
                }
                else {
                    MBProgressHUD.showTextDialog(self.view, message: "登陆失败")
                }
                

            
            }, failure: { (operation:AFHTTPRequestOperation?, error:Error?) in
                
            })
            
            
            
        
        }
    }
    


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
